package com.itheima.server.controller;

import com.itheima.domain.Comment;
import com.itheima.server.service.CommentsService;
import com.itheima.vo.PageResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Resource
    private CommentsService commentsService;

    /**
     * 获取评论列表
     * @param movementId
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping
    public ResponseEntity<PageResult> comments(String movementId, @RequestParam(defaultValue = "1") Integer page,
                                               @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pageResult = commentsService.comments(movementId,page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 发布评论
     * @return
     */
    @PostMapping
    public ResponseEntity<String> publishComments(@RequestBody Map<String,String> map){
        commentsService.publishComments(map.get("movementId"), map.get("comment"));
        return ResponseEntity.ok("OK");
    }



}
